package com.sharp.schedule.dao.repository;

import com.github.pagehelper.PageInfo;
import com.sharp.kernel.mybatis.repository.BaseMysqlRepository;
import com.sharp.schedule.dao.entity.SaScheduleHistory;
import com.sharp.schedule.dao.mapper.SaScheduleHistoryDao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Title: SaScheduleHistoryService
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2020/10/16 16:53
 */
@Service
public class SaScheduleHistoryService extends BaseMysqlRepository<SaScheduleHistory, SaScheduleHistoryDao> {

    @Resource
    private SaScheduleHistoryDao saScheduleHistoryDao;

    public PageInfo<SaScheduleHistory> queryScheduleHistory(Integer scheduleId, String result, Date startAt, Date endAt,
                                                            int currentPage, int pageSize) {
        Example example = super.getExample();
        Example.Criteria criteria = example.createCriteria();
        if (scheduleId != null) {
            criteria.andEqualTo("scheduleId", scheduleId);
        }
        if (StringUtils.isNotBlank(result)) {
            criteria.andEqualTo("result", result);
        }
        if (startAt != null) {
            criteria.andGreaterThanOrEqualTo("runAt", startAt);
        }
        if (endAt != null) {
            criteria.andLessThanOrEqualTo("runAt", endAt);
        }
        example.orderBy("finishAt").desc();
        return super.select(example, currentPage, pageSize);
    }


}


